package com.zhike.b2b.data;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.saas.biz.commen.CommMethodMgr;
import com.saas.biz.commen.DwindlePic;
import com.saas.biz.dao.attachDAO.AttachDAO;
import com.saas.biz.dao.attachDAO.AttachExt;
import com.saas.biz.paramMgr.ParamInfo;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.exp.SaasApplicationException;
import com.zhike.b2b.base.BaseService;
import com.zhike.b2b.dao.Dbtable;

@Service
public class Attachinfo extends BaseService
{
  Logger log = LoggerFactory.getLogger(Attachinfo.class);
  CommMethodMgr commen = new CommMethodMgr();
  ArrayList queryResult = new ArrayList();
  Buffers inBuffer;
  Buffers outBuffer;
  Dbtable tradeQuery = new Dbtable();

  public void setTradeQuery(Dbtable paramDbtable)
  {
    this.tradeQuery = paramDbtable;
  }

  public Dbtable getTradeQuery()
  {
    return this.tradeQuery;
  }

  public void setOutBuffer(Buffers paramBuffers)
  {
    this.outBuffer = paramBuffers;
  }

  public Buffers getOutBuffer()
  {
    return this.outBuffer;
  }

  public ArrayList getQueryResult()
  {
    return this.queryResult;
  }

  public void setQueryResult(ArrayList paramArrayList)
  {
    this.queryResult = paramArrayList;
  }

  public ArrayList getCustHonourList(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString1);
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", paramString2);
    localAttachExt.setParam(":VMODEL", paramString3);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_THREE");
    return localArrayList;
  }

  public ArrayList getAttachInfoByList(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ROOT_ID");
    return localArrayList;
  }

  public ArrayList getAttachInfoById(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ATTACH_ROOT_ID");
    return localArrayList;
  }

  public ArrayList getAttachInfo(String paramString1, String paramString2)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    ArrayList localArrayList = localAttachExt.selByList("SEL_ATTACH_BY_ROOT_ID");
    return localArrayList;
  }

  public String getAttachPath(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    String str = "";
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    localAttachExt.setParam(":VVALIDITY", paramString3);
    localArrayList = localAttachExt.selByList("SEL_BY_ROOT");
    if (localArrayList == null)
    {
      str = "/images/default_wood.gif";
      return str;
    }
    Iterator localIterator = localArrayList.iterator();
    HashMap localHashMap = (HashMap)localIterator.next();
    if (localHashMap.get("file_path") != "")
      str = localHashMap.get("file_path").toString();
    else
      str = "/upload/default.gif";
    return str;
  }

  public String getAttachPathByUserFace(String paramString)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    String str = "";
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString);
    localAttachExt.setParam(":VFILE_TYPE", "U");
    localAttachExt.setParam(":VVALIDITY", "0");
    localArrayList = localAttachExt.selByList("SEL_BY_ROOT");
    if (localArrayList == null)
    {
      str = "/upload/UserDefault.gif";
      return str;
    }
    Iterator localIterator = localArrayList.iterator();
    HashMap localHashMap = (HashMap)localIterator.next();
    if (localHashMap.get("file_path") != "")
      str = localHashMap.get("file_path").toString();
    else
      str = "/upload/UserDefault.gif";
    return str;
  }

  public ArrayList getAttachList(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    localAttachExt.setParam(":VVALIDITY", paramString3);
    localArrayList = localAttachExt.selByList("SEL_BY_ROOT");
    return localArrayList;
  }

  public ArrayList getAttachInfo(String paramString)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ID", paramString);
    localArrayList = localAttachExt.selByList("SEL_BY_ID");
    return localArrayList;
  }

  public int addHonour(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    String str = new CommMethodMgr().GenTradeId();
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VCUST_ID", paramBuffers.getString("SESSION_CUST_ID"));
    localAttachExt.setParam(":VUSER_ID", paramBuffers.getString("SESSION_USER_ID"));
    localAttachExt.setParam(":VATTACH_ID", str);
    localAttachExt.setParam(":VMODEL", paramBuffers.getString("MODEL"));
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", paramBuffers.getString("ATTACH_ROOT_TYPE"));
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramBuffers.getString("ATTACH_ROOT_ID"));
    localAttachExt.setParam(":VFILE_PATH", paramBuffers.getString("FILE_PATH"));
    localAttachExt.setParam(":VFILE_TYPE", paramBuffers.getString("FILE_TYPE"));
    localAttachExt.setParam(":VATTACH_NAME", paramBuffers.getString("ATTACH_NAME"));
    log.debug("==============" + paramBuffers.getString("ATTACH_NAME"));
    log.debug("==============" + paramBuffers.getString("SESSION_CUST_ID"));
    log.debug("==============" + paramBuffers.getString("SESSION_USER_ID"));
    log.debug("==============" + str);
    log.debug("==============" + paramBuffers.getString("MODEL"));
    log.debug("==============" + paramBuffers.getString("ATTACH_ROOT_TYPE"));
    log.debug("==============" + paramBuffers.getString("ATTACH_ROOT_ID"));
    log.debug("==============" + paramBuffers.getString("FILE_PATH"));
    log.debug("==============" + paramBuffers.getString("FILE_TYPE"));
    this.tradeQuery.executeBy(localAttachExt.insBy("INS_HONOUR"));
    return 0;
  }

  public int addAttachinfo(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    String str1 = new CommMethodMgr().GenTradeId();
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VCUST_ID", paramBuffers.getString("SESSION_CUST_ID"));
    localAttachExt.setParam(":VUSER_ID", paramBuffers.getString("SESSION_USER_ID"));
    localAttachExt.setParam(":VATTACH_ID", str1);
    localAttachExt.setParam(":VATTACH_DESC", paramBuffers.getString("ATTACH_DESC") == null ? paramBuffers.getString("ATTACH_DESC") : "");
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", paramBuffers.getString("ATTACH_ROOT_TYPE") == null ? paramBuffers.getString("ATTACH_ROOT_TYPE") : "");
    localAttachExt.setParam(":VMODEL", paramBuffers.getString("MODEL") == null ? paramBuffers.getString("MODEL") : "");
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramBuffers.getString("ATTACH_ID"));
    localAttachExt.setParam(":VFILE_PATH", paramBuffers.getString("FILE_PATH"));
    String str2 = paramBuffers.getString("FILE_TYPE");
    if (str2.equals("picture"))
      str2 = "0";
    localAttachExt.setParam(":VFILE_TYPE", Integer.valueOf(0));
    if (paramBuffers.getString("FILE_PATH").length() > 0)
      this.tradeQuery.executeBy(localAttachExt.insBy("INS_BY_ALL"));
    return 0;
  }

  public int amendAttachinfo(Buffers paramBuffers)
    throws SaasApplicationException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    AttachExt localAttachExt = new AttachExt();
    String str1 = new CommMethodMgr().GenTradeId();
    localAttachExt.setParam(":VATTACH_ID", str1);
    localAttachExt.setParam(":VCUST_ID", paramBuffers.getString("CUST_ID"));
    localAttachExt.setParam(":VUSER_ID", paramBuffers.getString("USER_ID"));
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramBuffers.getString("ATTACH_ID"));
    localAttachExt.setParam(":VFILE_PATH", paramBuffers.getString("FILE_PATH_NOW"));
    String str2 = paramBuffers.getString("FILE_TYPE");
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", paramBuffers.getString("ATTACH_ROOT_TYPE") == null ? paramBuffers.getString("ATTACH_ROOT_TYPE") : "");
    localAttachExt.setParam(":VMODEL", paramBuffers.getString("MODEL") == null ? paramBuffers.getString("MODEL") : "");
    if (str2.equals("picture"))
      str2 = "0";
    localAttachExt.setParam(":VFILE_TYPE", Integer.valueOf(0));
    String str3 = paramBuffers.getString("FILE_PATH_OLD");
    String str4 = paramBuffers.getString("FILE_PATH_NOW");
    if (!str3.equals(str4))
    {
      log.debug("==============00000000000000111111111111===========" + paramBuffers.getString("FILE_PATH_NOW"));
      if (!str3.equals(""))
        this.tradeQuery.executeBy(localAttachExt.insBy("DELETE_ATTACH_BY_ID"));
      if (!str4.equals(""))
      {
        log.debug("============11111111111111=============" + paramBuffers.getString("FILE_PATH_NOW"));
        this.tradeQuery.executeBy(localAttachExt.insBy("INS_BY_ALL"));
      }
    }
    return 0;
  }

  public int addAttachinfo(AttachDAO paramAttachDAO, String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    CommMethodMgr localcommMethodMgr = new CommMethodMgr();
    String str1 = localcommMethodMgr.GenTradeId();
    String[] arrayOfString = paramAttachDAO.getFile_path().trim().split("/");
    String str2 = arrayOfString[(arrayOfString.length - 1)];
    String str3 = "";
    if (paramAttachDAO.getFile_type() == 0)
      str3 = "/upload/" + paramAttachDAO.getCust_id() + "/图片/" + str2;
    localAttachExt.setParam(":VATTACH_ID", str1);
    localAttachExt.setParam(":VATTACH_NAME", str2);
    localAttachExt.setParam(":VFILE_PATH", str3);
    localAttachExt.setParam(":VUSER_ID", paramAttachDAO.getUser_id());
    localAttachExt.setParam(":VCUST_ID", paramAttachDAO.getCust_id());
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramAttachDAO.getAttach_root_id());
    localAttachExt.setParam(":VFILE_TYPE", Integer.valueOf(paramAttachDAO.getFile_type()));
    localAttachExt.setParam(":VATTACH_DESC", paramAttachDAO.getAttach_desc());
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", "");
    localAttachExt.setParam(":VMODEL", "");
    this.tradeQuery.executeBy(localAttachExt.insBy("INS_BY_ALL"));
    this.outBuffer.setString("FILENAME", "/upload/" + paramAttachDAO.getUser_id() + "/" + str2);
    return 0;
  }

  public String createImg(String paramString1, int paramInt1, int paramInt2, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6)
  {
    DwindlePic localDwindlePic = new DwindlePic();
    String str1 = paramString6;
    if (str1.equals("0"))
      str1 = "picture";
    if (str1.equals("1"))
      str1 = "attach";
    String str2 = "";
    ParamInfo localParamInfo = new ParamInfo();
    try
    {
      str2 = localParamInfo.getParameter("yinroot_path");
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      localSaasApplicationException.printStackTrace();
    }
    String str3 = (str2 + paramString2 + "/" + paramString1).replace('/', '\\');
    if (paramString3.equals("middle"))
      paramString1 = paramString1.substring(0, paramString1.lastIndexOf(".")) + "_middle." + paramString1.substring(paramString1.lastIndexOf(".") + 1, paramString1.length());
    if (paramString3.equals("small"))
      paramString1 = paramString1.substring(0, paramString1.lastIndexOf(".")) + "_small." + paramString1.substring(paramString1.lastIndexOf(".") + 1, paramString1.length());
    String str4 = (str2 + paramString2 + "/" + str1 + "/" + paramString5 + "/" + paramString4 + "/" + paramString1).replace('/', '\\');
    String str5 = (str2 + paramString2 + "/" + str1 + "/" + paramString5 + "/" + paramString4).replace('/', '\\');
    File localFile = new File(str5);
    if (!localFile.exists())
      try
      {
        localFile.mkdirs();
      }
      catch (Exception localException1)
      {
        this.log.error("创建文件夹失败！");
      }
    log.debug(str5 + "=folder");
    log.debug(str3 + "=oldImagPath");
    log.debug(str4 + "=newImagePath");
    try
    {
      localDwindlePic.doZoom(paramInt1, paramInt2, str3, str4);
    }
    catch (Exception localException2)
    {
      throw new RuntimeException(localException2);
    }
    return str4;
  }

  public void amendImg(String paramString)
  {
    File localFile1 = new File(paramString);
    localFile1.delete();
    String str1 = paramString.substring(0, paramString.lastIndexOf(".")) + "_middle." + paramString.substring(paramString.lastIndexOf(".") + 1, paramString.length());
    File localFile2 = new File(str1);
    localFile2.delete();
    String str2 = paramString.substring(0, paramString.lastIndexOf(".")) + "_small." + paramString.substring(paramString.lastIndexOf(".") + 1, paramString.length());
    File localFile3 = new File(str2);
    localFile3.delete();
  }

  public void addAttachInfo(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str1 = "";
    if ((paramBuffers.getString("RSRV_STR2") != null) || (paramBuffers.getString("RSRV_STR2") == ""))
      str1 = paramBuffers.getString("RSRV_STR2");
    String str2 = paramBuffers.getString("SESSION_CUST_ID");
    String str3 = paramBuffers.getString("SESSION_USER_ID");
    String str4 = paramBuffers.getString("ATTACH_ROOT_ID");
    String str5 = paramBuffers.getString("FILE_TYPE");
    if (str5.equals(""))
      str5 = "0";
    String str6 = paramBuffers.getString("FILE_PATH");
    String str7 = paramBuffers.getString("FILE_NAME") != null ? paramBuffers.getString("FILE_NAME") : "";
    String str8 = paramBuffers.getString("ATTACH_ROOT_TYPE") != null ? paramBuffers.getString("ATTACH_ROOT_TYPE") : "";
    String str9 = paramBuffers.getString("MODEL") != null ? paramBuffers.getString("MODEL") : "";
    String str10 = paramBuffers.getString("ATTACH_DESC") != null ? paramBuffers.getString("ATTACH_DESC") : "";
    try
    {
      AttachDAO localAttachDAO = new AttachDAO();
      localAttachDAO.setAttach_root_id(str4);
      localAttachDAO.setFile_type(new Integer(str5).intValue());
      localAttachDAO.setUser_id(str3);
      localAttachDAO.setCust_id(str2);
      localAttachDAO.setFile_path(str6);
      localAttachDAO.setAttach_root_type(str8);
      localAttachDAO.setModel(str9);
      localAttachDAO.setAttach_name(str7);
      localAttachDAO.setAttach_desc(str10);
      localAttachDAO.setRsrv_str2(str1);
      localAttachDAO.setCompany_url(str1);
      i = addAttachInfo(localAttachDAO);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int addAttachInfo(AttachDAO paramAttachDAO)
    throws SaasApplicationException
  {
    CommMethodMgr localcommMethodMgr = new CommMethodMgr();
    AttachExt localAttachExt = new AttachExt();
    ParamInfo localParamInfo = new ParamInfo();
    if ((paramAttachDAO.getRsrv_str2() == "1") || (paramAttachDAO.getRsrv_str2().equals("1")))
    {
      String str = localParamInfo.getParameter("yinpath");
      DwindlePic localDwindlePic = new DwindlePic();
      localDwindlePic.ImgYin(str, paramAttachDAO.getFile_path());
    }
    String str = paramAttachDAO.getAttach_root_id();
    localAttachExt.setParam(":VFILE_TYPE", Integer.valueOf(paramAttachDAO.getFile_type()));
    localAttachExt.setParam(":VATTACH_ID", localcommMethodMgr.GenTradeId());
    localAttachExt.setParam(":VUSER_ID", paramAttachDAO.getUser_id());
    localAttachExt.setParam(":VCUST_ID", paramAttachDAO.getCust_id());
    localAttachExt.setParam(":VATTACH_ROOT_ID", str);
    localAttachExt.setParam(":VATTACH_NAME", paramAttachDAO.getAttach_name());
    localAttachExt.setParam(":VATTACH_DESC", paramAttachDAO.getAttach_desc());
    localAttachExt.setParam(":VRSRV_STR2", paramAttachDAO.getCompany_url());
    localAttachExt.setParam(":VFILE_PATH", paramAttachDAO.getFile_path());
    localAttachExt.setParam(":VVALIDITY", "0");
    localAttachExt.setParam(":VATTACH_ROOT_TYPE", paramAttachDAO.getAttach_root_type());
    localAttachExt.setParam(":VMODEL", paramAttachDAO.getModel());
    if ((paramAttachDAO.getAttach_name() == null) || (paramAttachDAO.getAttach_name().equals("")))
    {
      this.tradeQuery.executeBy(localAttachExt.insBy("INS_BY_ALL"));
      log.debug("一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一");
    }
    else
    {
      log.debug("二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二");
      this.tradeQuery.executeBy(localAttachExt.insBy("INS_BY_ALLS"));
    }
    return 0;
  }

  public ArrayList getAttachInfoByList(String paramString1, String paramString2)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ROOT_ID_FILE");
    return localArrayList;
  }

  public ArrayList getAttachInfoByList(int paramInt1, int paramInt2, String paramString1, String paramString2)
    throws SaasApplicationException
  {
    if (paramInt1 > 1)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    else
      paramInt1 = 0;
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ROOT_ID_FILE", paramInt1, paramInt2);
    return localArrayList;
  }
  /**
   * 根据RootId统计附件个数
   * @param paramString1
   * @return
   * @throws SaasApplicationException
   */
  public int countAttachInfoById(String paramString1)
  throws SaasApplicationException
{
   String sql = " select count(*) from attach where attach_root_id= "+paramString1 ;
   return jt.queryForInt(sql);
}

  public String getAttachInfoBy(String paramString1, String paramString2)
    throws SaasApplicationException
  {
    String str = "/include/htmltag/images/errorimg.gif";
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString1);
    localAttachExt.setParam(":VFILE_TYPE", paramString2);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ROOT_ID_FILE");
    if (localArrayList != null)
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      if (localHashMap.get("file_path") != null)
        str = localHashMap.get("file_path").toString();
    }
    return str;
  }

  public void deletefile(String paramString)
  {
    ParamInfo localParamInfo = new ParamInfo();
    String str1 = "";
    String str2 = "";
    try
    {
      str2 = localParamInfo.getParameter("mysqlbase.rootpath");
      str1 = getFilePathByAttachId(paramString);
    }
    catch (SaasApplicationException localSaasApplicationException)
    {
      localSaasApplicationException.printStackTrace();
    }
    if (!str1.equals(""))
    {
      File localFile = new File(str2 + str1);
      localFile.delete();
    }
  }

  public void delAttachInfo(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str = paramBuffers.getStringWeb("ATTACH_ID");
    deletefile(str);
    try
    {
      i = delAttachInfo(str);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int delAttachInfo(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ID", paramString);
    this.tradeQuery.executeBy(localAttachExt.insBy("DELETE_BY_ID"));
    return 0;
  }

  public void delAttachByRootId(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str = paramBuffers.getStringWeb("ATTACH_ROOT_ID");
    try
    {
      i = delAttachInfo(str);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int delAttachByRootId(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString);
    this.tradeQuery.executeBy(localAttachExt.insBy("DELETE_BY_ROOT"));
    return 0;
  }

  public ArrayList getAttachInfo(int paramInt)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    localArrayList = localAttachExt.selByList("SEL_BY_JPG", 0, paramInt);
    return localArrayList;
  }

  public ArrayList getFilePath(String paramString)
    throws SaasApplicationException
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString);
    localArrayList = localAttachExt.selByList("SEL_BY_ATTACH_ROOT_ID");
    return localArrayList;
  }

  public String getFilePathClass(String paramString)
    throws SaasApplicationException
  {
    String str = "";
    ArrayList localArrayList = new ArrayList();
    localArrayList = getFilePath(paramString);
    if (localArrayList != null)
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      if (localHashMap.get("file_path") != null)
        str = localHashMap.get("file_path").toString();
    }
    return str;
  }

  public void delAttachInfoCompany(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str = paramBuffers.getStringWeb("CUST_ID");
    try
    {
      i = delAttachInfoCompany(str);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int delAttachInfoCompany(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VCUST_ID", paramString);
    this.tradeQuery.executeBy(localAttachExt.insByCompany("DELETE_BY_ID_FROM_COMPANY"));
    return 0;
  }

  public ArrayList getAttachInfoByListTemp(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ROOT_ID");
    return localArrayList;
  }

  public String getPicFilePath(String paramString)
    throws SaasApplicationException
  {
    String str = "";
    ArrayList localArrayList = getAttachInfoByListTemp(paramString);
    if (localArrayList != null)
      for (int i = 0; i < localArrayList.size(); i++)
      {
        HashMap localHashMap = (HashMap)localArrayList.get(i);
        if ((localHashMap.get("file_path") == null) || (checkPicType(localHashMap.get("file_path").toString()) != 0))
          continue;
        str = localHashMap.get("file_path").toString();
      }
    return str;
  }

  public int checkPicType(String paramString)
  {
    String str = paramString.substring(paramString.lastIndexOf(".") + 1, paramString.length()).toLowerCase();
    if (str.equals("gif"))
      return 0;
    if (str.equals("jpeg"))
      return 0;
    if (str.equals("jpg"))
      return 0;
    if (str.equals("bmp"))
      return 0;
    return 1;
  }

  public String getAttachNameByAttachId(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ATTACH_ID");
    String str1 = "";
    String str2 = "";
    String str3 = "";
    int i = 0;
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      str1 = localHashMap.get("file_path").toString() != null ? localHashMap.get("file_path").toString() : str1;
      str2 = localHashMap.get("attach_name").toString() != null ? localHashMap.get("attach_name").toString() : str2;
    }
    if ((str1 != null) || (!str1.equals("")))
    {
      i = str1.lastIndexOf(".");
      str3 = str1.substring(i + 1, str1.length());
      str2 = str2 + "." + str3;
    }
    return str2;
  }

  public String getFilePathByAttachId(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_BY_ATTACH_ID");
    String str = "";
    int i = 0;
    if ((localArrayList != null) && (localArrayList.size() > 0))
    {
      HashMap localHashMap = (HashMap)localArrayList.get(0);
      str = localHashMap.get("file_path").toString() != null ? localHashMap.get("file_path").toString() : str;
    }
    return str;
  }

  public void delVedioInfo(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str = paramBuffers.getStringWeb("ATTACH_ID");
    try
    {
      i = delVedioInfo(str);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int delVedioInfo(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    ArrayList localArrayList = new ArrayList();
    String str1 = "";
    String str2 = "";
    String str3 = "";
    str2 = new ParamInfo().getParameter("yinroot_path");
    localAttachExt.setParam(":VATTACH_ID", paramString);
    if ((paramString != null) && (!paramString.equals("")))
      localArrayList = new Attachinfo().getAttachInfoByAttachId(paramString);
    if ((localArrayList != null) && (localArrayList.size() > 0))
      for (int i = 0; i < localArrayList.size(); i++)
      {
        HashMap localHashMap = (HashMap)localArrayList.get(i);
        if (localHashMap.get("file_path") == null)
          continue;
        str1 = localHashMap.get("file_path").toString();
        if (str1.equals(""))
          continue;
        str3 = str2 + str1;
        File localFile = new File(str3);
        localFile.delete();
      }
    this.tradeQuery.executeBy(localAttachExt.insBy("DELETE_BY_ID"));
    return 0;
  }

  public ArrayList getAttachInfoByAttachId(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VROOT_ID", paramString);
    ArrayList localArrayList = localAttachExt.selByList("SEL_VEDIO_BY_ROOT_ID");
    return localArrayList;
  }

  public void updateVedioInfo(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str1 = paramBuffers.getStringWeb("ATTACH_ID");
    String str2 = paramBuffers.getString("ATTACH_DESC_UPDATE");
    str2 = new String(str2.getBytes("ISO-8859-1"), "UTF-8");
    String str3 = paramBuffers.getString("LINK_ADDR");
    str3 = new String(str3.getBytes("ISO-8859-1"), "UTF-8");
    try
    {
      i = updateVedioInfo(str1, str2, str3);
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int updateVedioInfo(String paramString1, String paramString2, String paramString3)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    localAttachExt.setParam(":VATTACH_ID", paramString1);
    localAttachExt.setParam(":VATTACH_DESC_UPDATE", paramString2);
    localAttachExt.setParam(":VRSRV_STR2", paramString3);
    this.tradeQuery.executeBy(localAttachExt.insBy("UPDATE_ATTACH_DESC_BY_ATTACH_ID"));
    return 0;
  }

  public ArrayList getAdviceInfo(String paramString, int paramInt1, int paramInt2)
  {
    if (paramInt1 > 1)
      paramInt1 = (paramInt1 - 1) * paramInt2;
    else
      paramInt1 = 0;
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    if ((paramString.trim().equals("")) || (paramString == null))
      localAttachExt.setParam(":VKEYWORD", "%");
    else
      localAttachExt.setParam(":VKEYWORD", "%" + paramString + "%");
    localArrayList = localAttachExt.selByList("SEL_ADVICE_INFO", paramInt1, paramInt2);
    return localArrayList;
  }

  public int getAdviceInfo(String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    AttachExt localAttachExt = new AttachExt();
    if ((paramString.trim().equals("")) || (paramString == null))
      localAttachExt.setParam(":VKEYWORD", "%");
    else
      localAttachExt.setParam(":VKEYWORD", "%" + paramString + "%");
    localArrayList = localAttachExt.selByList("SEL_ADVICE_INFO");
    if ((localArrayList != null) && (localArrayList.size() > 0))
      return localArrayList.size();
    return 0;
  }

  public void delAdviceInfos(Buffers paramBuffers)
    throws IOException
  {
    this.outBuffer = paramBuffers;
    this.inBuffer = paramBuffers;
    int i = -1;
    String str = paramBuffers.getStringWeb("ATTACH_ROOT_ID");
    try
    {
      StringTokenizer localStringTokenizer = new StringTokenizer(str, "|");
      while (localStringTokenizer.hasMoreElements())
        i = delAdviceInfos(localStringTokenizer.nextToken());
    }
    catch (SaasApplicationException saex)
    {
      this.log.error(saex.getMessage());
    }
    if (i != 0)
    {
      this.outBuffer.setInt("RESULT_CODE", -1);
      this.outBuffer.setString("RESULT_INFO", "业务处理失败！");
    }
    else
    {
      this.outBuffer.setInt("RESULT_CODE", 0);
      this.outBuffer.setString("RESULT_INFO", "业务处理成功！");
    }
  }

  public int delAdviceInfos(String paramString)
    throws SaasApplicationException
  {
    AttachExt localAttachExt = new AttachExt();
    ArrayList localArrayList = new ArrayList();
    String str1 = "";
    String str2 = "";
    String str3 = "";
    str2 = new ParamInfo().getParameter("yinroot_path");
    localAttachExt.setParam(":VATTACH_ROOT_ID", paramString);
    if ((paramString != null) && (!paramString.equals("")))
      localArrayList = new Attachinfo().getAttachInfoByList(paramString);
    if ((localArrayList != null) && (localArrayList.size() > 0))
      for (int i = 0; i < localArrayList.size(); i++)
      {
        HashMap localHashMap = (HashMap)localArrayList.get(i);
        if (localHashMap.get("file_path") == null)
          continue;
        str1 = localHashMap.get("file_path").toString();
        if (str1.equals(""))
          continue;
        str3 = str2 + str1;
        File localFile = new File(str3);
        localFile.delete();
      }
    this.tradeQuery.executeBy(localAttachExt.insBy("DELETE_BY_ATTACH_ROOT_ID"));
    return 0;
  }

  public String getPic(String paramString1, String paramString2)
  {
    String picName = "";
    try
    {
      String sql = "select " + paramString2 + " from attach where attach_root_id='" + paramString1 + "'";
      picName = jt.queryForObject(sql, new RowMapper<String>(){
 
		public String mapRow(ResultSet rs, int arg1) throws SQLException {
			 return rs.getString(1);
		}
    	  
      });
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return picName;
  }
}

